package leetcodev1.字符串;

public class LeetCode58 {
    //倒叙查找 遇到一个空格结束
    public int lengthOfLastWord(String s) {
        int length = s.length(), index = length - 1, ret = 0;
        //过滤空格
        while (index >= 0 && s.charAt(index) == ' ') {
            index--;
        }
        //非空格++
        while (index >= 0 && s.charAt(index) != ' ') {
            ret++;
            index--;
        }
        return ret;
    }
}
